Stabilize derivatives in fatiando.gravmag #196
Conversation
I found an error in the way This might impact some functions but it will be restricted mostly to the FFT derivatives so I'll make the fix in this branch. |
Padding helps reduce edge effects of the derivatives. Use the edge values to pad the array to the nearest power of two (almost, actually).
Was using ny, nx = shape when in fact x is north-south so shape = nx, ny
gridder.regular is generating grids the wrong way. The shape should be (nx, ny), not (ny, nx). Thus, the derivatives are in the wrong direction and the tests fail.
The Euler deconvolution tests were using FFT derivatives and failing because of them. I exchanged for derivatives approximated by finite differences in the forward modeling. This was the Euler tests don't depend of the performance of the FFT derivs.
This is how it should be. It breaks the tests for gravmag.sphere which were hardcoded numbers as doctests. Now the numbers are out of order so the test fail. Need a better test for this.
These tests weren't helping much. They compared the output to previous output. There are better tests comparing numpy and Cython implementations in the unit tests.
Filled the missing arguments in the docstrings and make explicit using fft derivs in the tests.
@mycarta here are the update results for this branch: Old resultsNew resultsGenerated using this notebook. Notice that the x and y derivatives are exchanged. There is a lot of confusion regarding this because we use x -> North-South in Fatiando and that is not always the case with other software. It's good to check that the results have the proper orientation that you'd expect. |
For the horizontal derivatives, the finite difference solutions are much more stable than the FFT ones. They underestimate the derivative a bit where the gradient is high but otherwise behave in a more consistent manner and are safer to use.
Hi Leo Thanks for the follow-up on derivatives. Could you please take the coordinates off from the images, and the notebook out altogether or use Those coordinates are from my unpublished thesis and not supposed to be out My apologies I should have said it clearly. In my tutorial I'd be using mock coordinates. Thanks Matteo On Thu, Apr 30, 2015 at 9:30 AM, Leonardo Uieda notifications@github.com
|
I'm so sorry about that! I should have noticed that your plots have no coordinates. It's fixed now. Also removed from the notebook (which doesn't include any data). |
If I'd mentioned it to begin with..... On Thu, Apr 30, 2015 at 10:54 AM, Leonardo Uieda notifications@github.com
|
Stabilize derivatives in fatiando.gravmag
@leouieda awesome pictures of smootheness |
Need to pull in some changes from upstream, particularly fatiando#196 which has made changes to `fatiando.gridder`, which this needs.
As pointed out by @mycarta in #194, the FFT-based derivative calculations in
fatiando.gravmag
are unstable (see the figure below for a comparison with the MATLAB derivatives).This PR tries to stabilize the derivatives by padding the input data and using different algorithms.
Fixes #194 and #167
Methods
The input data grids for FFT derivatives are padded using
numpy.pad
with the values in the borders of the grid. The padding is done to the nearest power of two. This solves the instabilities in the z derivative (specially in the edges). The horizontal derivatives are a bit better but still suffer from the "striping" seen above.Horizontal derivatives can be stabilized by using a central differences scheme instead of the FFT. This is what matlab uses to get the stable derivatives seen in the figure. The
derivx
andderivy
functions will have options to use the finite differences instead of FFT.Checklist:
doc/contributors.rst
(leave for last)gridder.regular